<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="box" index = "1"></div>
    <div data-index="2"></div>
    <script>
        //1.获取元素
        var box = document.querySelector('div');
        //1.获取内置属性和自定义属性
        console.log('内置属性=====' + box.className);
        console.log('内置属性=====' + box.getAttribute('class'));
        console.log('自定义属性===' + box.getAttribute('index'));
        console.log('--------------------');
        //2.修改内置属性和自定义属性的值
        box.className = 'box-update';
        console.log('内置属性=====' + box.className);
        box.setAttribute('class', 'box-update2');
        console.log('内置属性=====' + box.getAttribute('class'));
        box.setAttribute('index','1111');
        console.log('自定义属性===' + box.getAttribute('index'));
        console.log('--------------------');
        //3.移出自定义属性
        box.removeAttribute('index');
    </script>
</body>
</html><section></section>